package cn.istartfinancial.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.BASE64Encoder;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author: Nzp
 * @date: 2018/8/31 9:35
 * @description: base64工具
 */
public class Base64Utils
{
    private static Logger logger = LoggerFactory.getLogger(Base64Utils.class);
    private static BASE64Encoder encoder = new BASE64Encoder();

    public static String ioToBase64(InputStream in) throws IOException
    {
        String strBase64 = null;
        try
        {
            byte[] bytes = new byte[in.available()];
            // 将文件中的内容读入到数组中
            in.read(bytes);
            //将字节流数组转换为字符串
            strBase64 = encoder.encode(bytes);
            in.close();
        } catch (IOException ioe)
        {
            logger.error("图片转64编码异常", ioe);
        }
        return strBase64;
    }
}
